set.seed(1111)
library(MatchIt)
library(dplyr)
library(ggplot2)
library(haven)
library(stargazer)
library(tableone)
library(Hmisc)
library(cem)
library(Matching)
library(car)
library(Zelig)
library(RColorBrewer)
library(arm)
setwd("~/Dropbox/AttorneyMainData")
data <- read_dta("Attorney.dta")
data$hysLaw <- car::recode(data$SchoolLawyerArgue,"'Harvard'=1;'Yale'=1;'Stanford'=1;'Columbia'=1;'Chicago'=1;else=0")
data$demPres <- car::recode(data$SGOrals,"'McCree'=1;'Lee'=0;'(Acting) Fried'=0;'Fried'=0;'(Acting) Bryson'=0;'Starr'=0;'Days'=1;'(Acting) Dellinger'=1;'Waxman'=1;'(Acting) Underwood'=0; 'Olson'=0;'(Acting) Clement'=0;'Clement'=0;'Garre'=0;'(Acting) Kneedler'=1;'Kagan'=1;'(Acting) Katyal'=1;'Verrilli'=1;'(Acting) Gershengorn'=1;'(Acting) Francisco'=1;'(Acting) Wall'=1; 'Francisco'=1")
##Bryson was acting for both Bush 1 and Reagan
data$demPres[data$SGOrals=="(Acting) Bryson" & data$term=="1992"] <- 1
data$NPO <- car::recode(data$NPriorOral,"'20+'=20")
data$logNPO <- log(1+data$NPO)
data$two <- recode(data$NPO,"0:1=0;2:20=1")
data$three <- recode(data$NPO,"0:2=0;3:20=1")
data$four <- recode(data$NPO,"0:3=0;4:20=1")
data$five <- recode(data$NPO,"0:4=0;5:20=1")
data$six <- recode(data$NPO,"0:5=0;6:20=1")
data$seven <- recode(data$NPO,"0:6=0;7:20=1")
data$eight <- recode(data$NPO,"0:7=0;8:20=1")
data$nine <- recode(data$NPO,"0:8=0;9:20=1")
data$ten <- recode(data$NPO,"0:9=0;10:20=1")
table(data$NPO)
table(data$two)
prop.table(table(data$hysLaw))
prop.table(table(ctLevel$hysLaw))
data$SGOralsCollapseF <- as.factor(data$SGOralsCollapse)
data$justiceNameF <- as.factor(data$justiceName)
data$ActingSGOrals <- as.numeric(factor(data$ActingSGOrals, ordered=F))-1
data$TopLawSchool <- as.numeric(factor(data$TopLawSchool, ordered=F))-1
data$DCFirm <- as.numeric(factor(data$DCFirm, ordered=F))-1
data$ClerkDummy <- as.numeric(factor(data$ClerkDummy, ordered=F))-1
data$OppPetOrResp <- as.numeric(factor(data$OppPetOrResp, ordered=F))-1
data$CriminalDummy <- as.numeric(factor(data$CriminalDummy, ordered=F))-1
data$CivLibDummy <- as.numeric(factor(data$CivLibDummy, ordered=F))-1
data$EconDummy <- as.numeric(factor(data$EconDummy, ordered=F))-1
data$Acela <- as.numeric(factor(data$Acela, ordered=F))-1
data$LawyerArgueOSG <- as.numeric(factor(data$LawyerArgueOSG, ordered=F))-1
data$GenderLawyerArgue <- as.numeric(factor(data$GenderLawyerArgue, ordered=F))-1
data$RaceLawyerArgue <- as.numeric(factor(data$RaceLawyerArgue, ordered=F))-1
data$IdeologyOppCounsel <- as.numeric(factor(data$IdeologyOppCounsel, ordered=F))-1
ctLevel <- subset(data, ct_level==1)
summary(data)
dim(data)

###SI, Figure A2
pdf("priorOral.pdf",width=15,height=6.6,paper='special') 
barplot(table(ctLevel$NPO),xlab="Number of Prior Oral Arguments",main="",col="gray70",ylim=c(0,800),ylab="Number of Cases")
dev.off()

####One ORAL ARGUMENTS
xvars<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres","justiceNameF")
data_nomiss <- data %>%  # MatchIt does not allow missing values
  dplyr::select(PriorOral, JVote, one_of(xvars)) %>%
  na.omit()
data_nomiss <- data.frame(data_nomiss)
xvars_case<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres")
data_case_nomiss <- ctLevel %>%  # MatchIt does not allow missing values
  dplyr::select(PriorOral, WhoWon, minWinning, unan, nearUnan, one_of(xvars_case)) %>%
  na.omit()
data_case_nomiss <- data.frame(data_case_nomiss)

match_justice_ext <- matchit(PriorOral ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp+justiceNameF,
                             method = "cem", data = data_nomiss)
summary(match_justice_ext)
dta_justice_ext <- match.data(match_justice_ext)

match_case_ext <- matchit(PriorOral ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp,
                          method = "cem", data = data_case_nomiss)
summary(match_case_ext)
dta_case_ext <- match.data(match_case_ext)

one_case <- glm(WhoWon~PriorOral, family="binomial", data = ctLevel)
one_case_m <- glm(WhoWon~PriorOral+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = ctLevel)
one_justice <- glm(JVote~PriorOral, family="binomial", data = data)
one_justice_m <- glm(JVote~PriorOral+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = data)
one_case_match <- glm(WhoWon~PriorOral, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
one_case_m_match <- glm(WhoWon~PriorOral+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
one_justice_match <- glm(JVote~PriorOral, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)
one_justice_m_match <- glm(JVote~PriorOral+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)

####TWO ORAL ARGUMENTS
xvars<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres","justiceNameF")
data_nomiss <- data %>%  # MatchIt does not allow missing values
  dplyr::select(two, JVote, one_of(xvars)) %>%
  na.omit()
data_nomiss <- data.frame(data_nomiss)
xvars_case<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres")
data_case_nomiss <- ctLevel %>%  # MatchIt does not allow missing values
  dplyr::select(two, WhoWon, minWinning, unan, nearUnan, one_of(xvars_case)) %>%
  na.omit()
data_case_nomiss <- data.frame(data_case_nomiss)

match_justice_ext <- matchit(two ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp+justiceNameF,
                             method = "cem", data = data_nomiss)
summary(match_justice_ext)
dta_justice_ext <- match.data(match_justice_ext)

match_case_ext <- matchit(two ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp,
                          method = "cem", data = data_case_nomiss)
summary(match_case_ext)
dta_case_ext <- match.data(match_case_ext)

two_case <- glm(WhoWon~two, family="binomial", data = ctLevel)
two_case_m <- glm(WhoWon~two+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = ctLevel)
two_justice <- glm(JVote~two, family="binomial", data = data)
two_justice_m <- glm(JVote~two+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = data)
two_case_match <- glm(WhoWon~two, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
two_case_m_match <- glm(WhoWon~two+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
two_justice_match <- glm(JVote~two, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)
two_justice_m_match <- glm(JVote~two+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)

####THREE ORAL ARGUMENTS
xvars<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres","justiceNameF")
data_nomiss <- data %>%  # MatchIt does not allow missing values
  dplyr::select(three, JVote, one_of(xvars)) %>%
  na.omit()
data_nomiss <- data.frame(data_nomiss)
xvars_case<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres")
data_case_nomiss <- ctLevel %>%  # MatchIt does not allow missing values
  dplyr::select(three, WhoWon, minWinning, unan, nearUnan, one_of(xvars_case)) %>%
  na.omit()
data_case_nomiss <- data.frame(data_case_nomiss)

match_justice_ext <- matchit(three ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp+justiceNameF,
                             method = "cem", data = data_nomiss)
summary(match_justice_ext)
dta_justice_ext <- match.data(match_justice_ext)

match_case_ext <- matchit(three ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp,
                          method = "cem", data = data_case_nomiss)
summary(match_case_ext)
dta_case_ext <- match.data(match_case_ext)

three_case <- glm(WhoWon~three, family="binomial", data = ctLevel)
three_case_m <- glm(WhoWon~three+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = ctLevel)
three_justice <- glm(JVote~three, family="binomial", data = data)
three_justice_m <- glm(JVote~three+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = data)
three_case_match <- glm(WhoWon~three, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
three_case_m_match <- glm(WhoWon~three+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
three_justice_match <- glm(JVote~three, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)
three_justice_m_match <- glm(JVote~three+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)


####FOUR ORAL ARGUMENTS
xvars<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres","justiceNameF")
data_nomiss <- data %>%  # MatchIt does not allow missing values
  dplyr::select(four, JVote, one_of(xvars)) %>%
  na.omit()
data_nomiss <- data.frame(data_nomiss)
xvars_case<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres")
data_case_nomiss <- ctLevel %>%  # MatchIt does not allow missing values
  dplyr::select(four, WhoWon, minWinning, unan, nearUnan, one_of(xvars_case)) %>%
  na.omit()
data_case_nomiss <- data.frame(data_case_nomiss)

match_justice_ext <- matchit(four ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp+justiceNameF,
                             method = "cem", data = data_nomiss)
summary(match_justice_ext)
dta_justice_ext <- match.data(match_justice_ext)

match_case_ext <- matchit(four ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp,
                          method = "cem", data = data_case_nomiss)
summary(match_case_ext)
dta_case_ext <- match.data(match_case_ext)

four_case <- glm(WhoWon~four, family="binomial", data = ctLevel)
four_case_m <- glm(WhoWon~four+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = ctLevel)
four_justice <- glm(JVote~four, family="binomial", data = data)
four_justice_m <- glm(JVote~four+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = data)
four_case_match <- glm(WhoWon~four, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
four_case_m_match <- glm(WhoWon~four+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
four_justice_match <- glm(JVote~four, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)
four_justice_m_match <- glm(JVote~four+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)


####FIVE ORAL ARGUMENTS
xvars<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres","justiceNameF")
data_nomiss <- data %>%  # MatchIt does not allow missing values
  dplyr::select(five, JVote, one_of(xvars)) %>%
  na.omit()
data_nomiss <- data.frame(data_nomiss)
xvars_case<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres")
data_case_nomiss <- ctLevel %>%  # MatchIt does not allow missing values
  dplyr::select(five, WhoWon, minWinning, unan, nearUnan, one_of(xvars_case)) %>%
  na.omit()
data_case_nomiss <- data.frame(data_case_nomiss)

match_justice_ext <- matchit(five ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp+justiceNameF,
                             method = "cem", data = data_nomiss)
summary(match_justice_ext)
dta_justice_ext <- match.data(match_justice_ext)

match_case_ext <- matchit(five ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp,
                          method = "cem", data = data_case_nomiss)
summary(match_case_ext)
dta_case_ext <- match.data(match_case_ext)

five_case <- glm(WhoWon~five, family="binomial", data = ctLevel)
five_case_m <- glm(WhoWon~five+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = ctLevel)
five_justice <- glm(JVote~five, family="binomial", data = data)
five_justice_m <- glm(JVote~five+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = data)
five_case_match <- glm(WhoWon~five, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
five_case_m_match <- glm(WhoWon~five+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
five_justice_match <- glm(JVote~five, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)
five_justice_m_match <- glm(JVote~five+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)


####SiX ORAL ARGUMENTS
xvars<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres","justiceNameF")
data_nomiss <- data %>%  # MatchIt does not allow missing values
  dplyr::select(six, JVote, one_of(xvars)) %>%
  na.omit()
data_nomiss <- data.frame(data_nomiss)
xvars_case<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres")
data_case_nomiss <- ctLevel %>%  # MatchIt does not allow missing values
  dplyr::select(six, WhoWon, minWinning, unan, nearUnan, one_of(xvars_case)) %>%
  na.omit()
data_case_nomiss <- data.frame(data_case_nomiss)

match_justice_ext <- matchit(six ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp+justiceNameF,
                             method = "cem", data = data_nomiss)
summary(match_justice_ext)
dta_justice_ext <- match.data(match_justice_ext)

match_case_ext <- matchit(six ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp,
                          method = "cem", data = data_case_nomiss)
summary(match_case_ext)
dta_case_ext <- match.data(match_case_ext)

six_case <- glm(WhoWon~six, family="binomial", data = ctLevel)
six_case_m <- glm(WhoWon~six+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = ctLevel)
six_justice <- glm(JVote~six, family="binomial", data = data)
six_justice_m <- glm(JVote~six+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = data)
six_case_match <- glm(WhoWon~six, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
six_case_m_match <- glm(WhoWon~six+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
six_justice_match <- glm(JVote~six, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)
six_justice_m_match <- glm(JVote~six+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)


####SEVEN ORAL ARGUMENTS
xvars<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres","justiceNameF")
data_nomiss <- data %>%  # MatchIt does not allow missing values
  dplyr::select(seven, JVote, one_of(xvars)) %>%
  na.omit()
data_nomiss <- data.frame(data_nomiss)
xvars_case<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres")
data_case_nomiss <- ctLevel %>%  # MatchIt does not allow missing values
  dplyr::select(seven, WhoWon, minWinning, unan, nearUnan, one_of(xvars_case)) %>%
  na.omit()
data_case_nomiss <- data.frame(data_case_nomiss)

match_justice_ext <- matchit(seven ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp+justiceNameF,
                             method = "cem", data = data_nomiss)
summary(match_justice_ext)
dta_justice_ext <- match.data(match_justice_ext)

match_case_ext <- matchit(seven ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp,
                          method = "cem", data = data_case_nomiss)
summary(match_case_ext)
dta_case_ext <- match.data(match_case_ext)

seven_case <- glm(WhoWon~seven, family="binomial", data = ctLevel)
seven_case_m <- glm(WhoWon~seven+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = ctLevel)
seven_justice <- glm(JVote~seven, family="binomial", data = data)
seven_justice_m <- glm(JVote~seven+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = data)
seven_case_match <- glm(WhoWon~seven, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
seven_case_m_match <- glm(WhoWon~seven+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
seven_justice_match <- glm(JVote~seven, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)
seven_justice_m_match <- glm(JVote~seven+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)


####EIGHT ORAL ARGUMENTS
xvars<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres","justiceNameF")
data_nomiss <- data %>%  # MatchIt does not allow missing values
  dplyr::select(eight, JVote, one_of(xvars)) %>%
  na.omit()
data_nomiss <- data.frame(data_nomiss)
xvars_case<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres")
data_case_nomiss <- ctLevel %>%  # MatchIt does not allow missing values
  dplyr::select(eight, WhoWon, minWinning, unan, nearUnan, one_of(xvars_case)) %>%
  na.omit()
data_case_nomiss <- data.frame(data_case_nomiss)

match_justice_ext <- matchit(eight ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp+justiceNameF,
                             method = "cem", data = data_nomiss)
summary(match_justice_ext)
dta_justice_ext <- match.data(match_justice_ext)

match_case_ext <- matchit(eight ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp,
                          method = "cem", data = data_case_nomiss)
summary(match_case_ext)
dta_case_ext <- match.data(match_case_ext)

eight_case <- glm(WhoWon~eight, family="binomial", data = ctLevel)
eight_case_m <- glm(WhoWon~eight+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = ctLevel)
eight_justice <- glm(JVote~eight, family="binomial", data = data)
eight_justice_m <- glm(JVote~eight+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = data)
eight_case_match <- glm(WhoWon~eight, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
eight_case_m_match <- glm(WhoWon~eight+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
eight_justice_match <- glm(JVote~eight, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)
eight_justice_m_match <- glm(JVote~eight+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)


####NINE ORAL ARGUMENTS
xvars<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres","justiceNameF")
data_nomiss <- data %>%  # MatchIt does not allow missing values
  dplyr::select(nine, JVote, one_of(xvars)) %>%
  na.omit()
data_nomiss <- data.frame(data_nomiss)
xvars_case<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres")
data_case_nomiss <- ctLevel %>%  # MatchIt does not allow missing values
  dplyr::select(nine, WhoWon, minWinning, unan, nearUnan, one_of(xvars_case)) %>%
  na.omit()
data_case_nomiss <- data.frame(data_case_nomiss)

match_justice_ext <- matchit(nine ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp+justiceNameF,
                             method = "cem", data = data_nomiss)
summary(match_justice_ext)
dta_justice_ext <- match.data(match_justice_ext)

match_case_ext <- matchit(nine ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp,
                          method = "cem", data = data_case_nomiss)
summary(match_case_ext)
dta_case_ext <- match.data(match_case_ext)

nine_case <- glm(WhoWon~nine, family="binomial", data = ctLevel)
nine_case_m <- glm(WhoWon~nine+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = ctLevel)
nine_justice <- glm(JVote~nine, family="binomial", data = data)
nine_justice_m <- glm(JVote~nine+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = data)
nine_case_match <- glm(WhoWon~nine, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
nine_case_m_match <- glm(WhoWon~nine+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
nine_justice_match <- glm(JVote~nine, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)
nine_justice_m_match <- glm(JVote~nine+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)


####TEN ORAL ARGUMENTS
xvars<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres","justiceNameF")
data_nomiss <- data %>%  # MatchIt does not allow missing values
  dplyr::select(ten, JVote, one_of(xvars)) %>%
  na.omit()
data_nomiss <- data.frame(data_nomiss)
xvars_case<-c("SGOralsCollapseF","ActingSGOrals","hysLaw","DCFirm","ClerkDummy","IdeologyOppCounsel","Rehnquist","Roberts","OppPetOrResp","demPres")
data_case_nomiss <- ctLevel %>%  # MatchIt does not allow missing values
  dplyr::select(ten, WhoWon, minWinning, unan, nearUnan, one_of(xvars_case)) %>%
  na.omit()
data_case_nomiss <- data.frame(data_case_nomiss)

match_justice_ext <- matchit(ten ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp+justiceNameF,
                             method = "cem", data = data_nomiss)
summary(match_justice_ext)
dta_justice_ext <- match.data(match_justice_ext)

match_case_ext <- matchit(ten ~ SGOralsCollapseF+ActingSGOrals+hysLaw+DCFirm+ClerkDummy+IdeologyOppCounsel+demPres+Rehnquist+Roberts+OppPetOrResp,
                          method = "cem", data = data_case_nomiss)
summary(match_case_ext)
dta_case_ext <- match.data(match_case_ext)

ten_case <- glm(WhoWon~ten, family="binomial", data = ctLevel)
ten_case_m <- glm(WhoWon~ten+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = ctLevel)
ten_justice <- glm(JVote~ten, family="binomial", data = data)
ten_justice_m <- glm(JVote~ten+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = data)
ten_case_match <- glm(WhoWon~ten, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
ten_case_m_match <- glm(WhoWon~ten+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres, family="binomial", data = match.data(match_case_ext), weights=match.data(match_case_ext)$weights)
ten_justice_match <- glm(JVote~ten, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)
ten_justice_m_match <- glm(JVote~ten+hysLaw+DCFirm+ClerkDummy+Rehnquist+Roberts+OppPetOrResp+IdeologyOppCounsel+demPres+justiceNameF, family="binomial", data = match.data(match_justice_ext), weights=match.data(match_justice_ext)$weights)

#dd <- data; predict(full_justice_m,data.frame(PriorOral=1,hysLaw=median(dd$hysLaw,na.omit=T),DCFirm=median(dd$DCFirm,na.omit=T),ClerkDummy=median(dd$ClerkDummy,na.omit=T),Rehnquist=median(dd$Rehnquist,na.omit=T),Roberts=median(dd$Roberts,na.omit=T),OppPetOrResp=median(dd$OppPetOrResp,na.omit=T),IdeologyOppCounsel=1,demPres=0,justiceNameF=tail(row.names(sort(table(dd$justiceNameF))),1)),type="response")-predict(full_justice_m,data.frame(PriorOral=0,hysLaw=median(dd$hysLaw,na.omit=T),DCFirm=median(dd$DCFirm,na.omit=T),ClerkDummy=median(dd$ClerkDummy,na.omit=T),Rehnquist=median(dd$Rehnquist,na.omit=T),Roberts=median(dd$Roberts,na.omit=T),OppPetOrResp=median(dd$OppPetOrResp,na.omit=T),IdeologyOppCounsel=1,demPres=0,justiceNameF=tail(row.names(sort(table(dd$justiceNameF))),1)),type="response")
#dd <- match.data(match_justice_ext);predict(ext_justice_m,data.frame(PriorOral=1,hysLaw=median(dd$hysLaw,na.omit=T),DCFirm=median(dd$DCFirm,na.omit=T),ClerkDummy=median(dd$ClerkDummy,na.omit=T),Rehnquist=median(dd$Rehnquist,na.omit=T),Roberts=median(dd$Roberts,na.omit=T),OppPetOrResp=median(dd$OppPetOrResp,na.omit=T),IdeologyOppCounsel=1,demPres=0,justiceNameF=tail(row.names(sort(table(dd$justiceNameF))),1)),type="response")-predict(ext_justice_m,data.frame(PriorOral=0,hysLaw=median(dd$hysLaw,na.omit=T),DCFirm=median(dd$DCFirm,na.omit=T),ClerkDummy=median(dd$ClerkDummy,na.omit=T),Rehnquist=median(dd$Rehnquist,na.omit=T),Roberts=median(dd$Roberts,na.omit=T),OppPetOrResp=median(dd$OppPetOrResp,na.omit=T),IdeologyOppCounsel=1,demPres=0,justiceNameF=tail(row.names(sort(table(dd$justiceNameF))),1)),type="response")
#dd <- ctLevel; predict(full_case_m,data.frame(PriorOral=1,hysLaw=median(dd$hysLaw,na.omit=T),DCFirm=median(dd$DCFirm,na.omit=T),ClerkDummy=median(dd$ClerkDummy,na.omit=T),Rehnquist=median(dd$Rehnquist,na.omit=T),Roberts=median(dd$Roberts,na.omit=T),OppPetOrResp=median(dd$OppPetOrResp,na.omit=T),IdeologyOppCounsel=1,demPres=0),type="response")-predict(full_case_m,data.frame(PriorOral=0,hysLaw=median(dd$hysLaw,na.omit=T),DCFirm=median(dd$DCFirm,na.omit=T),ClerkDummy=median(dd$ClerkDummy,na.omit=T),Rehnquist=median(dd$Rehnquist,na.omit=T),Roberts=median(dd$Roberts,na.omit=T),OppPetOrResp=median(dd$OppPetOrResp,na.omit=T),IdeologyOppCounsel=1,demPres=0),type="response")
#dd <- match.data(match_case_ext);predict(ext_case_m,data.frame(PriorOral=1,hysLaw=median(dd$hysLaw,na.omit=T),DCFirm=median(dd$DCFirm,na.omit=T),ClerkDummy=median(dd$ClerkDummy,na.omit=T),Rehnquist=median(dd$Rehnquist,na.omit=T),Roberts=median(dd$Roberts,na.omit=T),OppPetOrResp=median(dd$OppPetOrResp,na.omit=T),IdeologyOppCounsel=1,demPres=0),type="response")-predict(ext_case_m,data.frame(PriorOral=0,hysLaw=median(dd$hysLaw,na.omit=T),DCFirm=median(dd$DCFirm,na.omit=T),ClerkDummy=median(dd$ClerkDummy,na.omit=T),Rehnquist=median(dd$Rehnquist,na.omit=T),Roberts=median(dd$Roberts,na.omit=T),OppPetOrResp=median(dd$OppPetOrResp,na.omit=T),IdeologyOppCounsel=1,demPres=0),type="response")

stargazer(one_justice_m,two_justice_m,three_justice_m,four_justice_m,five_justice_m,digits=2,star.cutoffs = c(.05))
stargazer(six_justice_m,seven_justice_m,eight_justice_m,nine_justice_m,ten_justice_m,digits=2,star.cutoffs = c(.05))
stargazer(one_justice_m_match,two_justice_m_match,three_justice_m_match,four_justice_m_match,five_justice_m_match,type="text",digits=2,star.cutoffs = c(.05))
stargazer(six_justice_m_match,seven_justice_m_match,eight_justice_m_match,nine_justice_m_match,ten_justice_m_match,digits=2,star.cutoffs = c(.05))

##Simulate
set.seed(1111)
dd <- data
aa <- sim(ten_justice_m)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"ten"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"ten"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
ten_j <- treated-untreated

aa <- sim(nine_justice_m)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"nine"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"nine"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
nine_j <- treated-untreated

aa <- sim(eight_justice_m)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"eight"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"eight"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
eight_j <- treated-untreated

aa <- sim(seven_justice_m)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"seven"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"seven"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
seven_j <- treated-untreated

aa <- sim(six_justice_m)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"six"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"six"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
six_j <- treated-untreated

aa <- sim(five_justice_m)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"five"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"five"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
five_j <- treated-untreated

aa <- sim(four_justice_m)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"four"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"four"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
four_j <- treated-untreated

aa <- sim(three_justice_m)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"three"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"three"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
three_j <- treated-untreated

aa <- sim(two_justice_m)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"two"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"two"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
two_j <- treated-untreated

aa <- sim(one_justice_m)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"PriorOral"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"PriorOral"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
one_j <- treated-untreated

##Matched
dd <- data
aa <- sim(ten_justice_m_match)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"ten"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"ten"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
ten_j_match <- treated-untreated

aa <- sim(nine_justice_m_match)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"nine"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"nine"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
nine_j_match <- treated-untreated

aa <- sim(eight_justice_m_match)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"eight"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"eight"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
eight_j_match <- treated-untreated

aa <- sim(seven_justice_m_match)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"seven"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"seven"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
seven_j_match <- treated-untreated

aa <- sim(six_justice_m_match)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"six"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"six"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
six_j_match <- treated-untreated

aa <- sim(five_justice_m_match)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"five"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"five"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
five_j_match <- treated-untreated

aa <- sim(four_justice_m_match)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"four"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"four"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
four_j_match <- treated-untreated

aa <- sim(three_justice_m_match)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"three"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"three"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
three_j_match <- treated-untreated

aa <- sim(two_justice_m_match)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"two"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"two"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
two_j_match <- treated-untreated

aa <- sim(one_justice_m_match)
acoef <- coef(aa)
treated <- invlogit(acoef[,"(Intercept)"] + acoef[,"PriorOral"]*1 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
untreated <- invlogit(acoef[,"(Intercept)"] + acoef[,"PriorOral"]*0 + acoef[,"hysLaw"]*median(dd$hysLaw,na.omit=T) + acoef[,"DCFirm"]*median(dd$DCFirm,na.omit=T) + acoef[,"ClerkDummy"]*median(dd$ClerkDummy,na.omit=T) + acoef[,"Rehnquist"]*1 + acoef[,"Roberts"]*0 + acoef[,"OppPetOrResp"]*median(dd$OppPetOrResp,na.omit=T) + acoef[,"IdeologyOppCounsel"]*1  + acoef[,"demPres"]*0 )
one_j_match <- treated-untreated

###Manuscript, Figure 6
pdf("Cutoffs.pdf",width=8,height=8,paper='special') 
par(mar=c(5.1,3.1, 4.1, 2.1),mfrow=c(1,1),oma=c(0,3,0,0))
#Unmatched Justice-Level, Multivariate
plot(NA,xlim=c(-.01,.18),ylim=c(.5,10.5),ylab="",xlab="ATT", yaxt="n")
axis(2, at=c(10,9,8,7,6,5,4,3,2,1),labels=c("Ten","Nine","Eight","Seven","Six","Five","Four","Three","Two","One"), las=2)
mtext("Number of Prior Arguments", side = 2, line=4)
points(y=c(10,9,8,7,6,5,4,3,2,1)+.1,x=c(mean(ten_j),
                                     mean(nine_j),
                                     mean(eight_j),
                                     mean(seven_j),
                                     mean(six_j),
                                     mean(five_j),
                                     mean(four_j),
                                     mean(three_j),
                                     mean(two_j),
                                     mean(one_j)), pch=19,cex=1.5,col="gray70")
segments(y0=10+.1,y1=10+.1,x0=quantile(ten_j,.025),x1=quantile(ten_j,.975),lwd=2,col="gray70")
segments(y0=9+.1,y1=9+.1,x0=quantile(nine_j,.025),x1=quantile(nine_j,.975),lwd=2,col="gray70")
segments(y0=8+.1,y1=8+.1,x0=quantile(eight_j,.025),x1=quantile(eight_j,.975),lwd=2,col="gray70")
segments(y0=7+.1,y1=7+.1,x0=quantile(seven_j,.025),x1=quantile(seven_j,.975),lwd=2,col="gray70")
segments(y0=6+.1,y1=6+.1,x0=quantile(six_j,.025),x1=quantile(six_j,.975),lwd=2,col="gray70")
segments(y0=5+.1,y1=5+.1,x0=quantile(five_j,.025),x1=quantile(five_j,.975),lwd=2,col="gray70")
segments(y0=4+.1,y1=4+.1,x0=quantile(four_j,.025),x1=quantile(four_j,.975),lwd=2,col="gray70")
segments(y0=3+.1,y1=3+.1,x0=quantile(three_j,.025),x1=quantile(three_j,.975),lwd=2,col="gray70")
segments(y0=2+.1,y1=2+.1,x0=quantile(two_j,.025),x1=quantile(two_j,.975),lwd=2,col="gray70")
segments(y0=1+.1,y1=1+.1,x0=quantile(one_j,.025),x1=quantile(one_j,.975),lwd=2,col="gray70")
points(y=c(10,9,8,7,6,5,4,3,2,1)-.1,x=c(mean(ten_j_match),
                                     mean(nine_j_match),
                                     mean(eight_j_match),
                                     mean(seven_j_match),
                                     mean(six_j_match),
                                     mean(five_j_match),
                                     mean(four_j_match),
                                     mean(three_j_match),
                                     mean(two_j_match),
                                     mean(one_j_match)), pch=18,cex=1.75)
segments(y0=10-.1,y1=10-.1,x0=quantile(ten_j_match,.025),x1=quantile(ten_j_match,.975),lwd=2)
segments(y0=9-.1,y1=9-.1,x0=quantile(nine_j_match,.025),x1=quantile(nine_j_match,.975),lwd=2)
segments(y0=8-.1,y1=8-.1,x0=quantile(eight_j_match,.025),x1=quantile(eight_j_match,.975),lwd=2)
segments(y0=7-.1,y1=7-.1,x0=quantile(seven_j_match,.025),x1=quantile(seven_j_match,.975),lwd=2)
segments(y0=6-.1,y1=6-.1,x0=quantile(six_j_match,.025),x1=quantile(six_j_match,.975),lwd=2)
segments(y0=5-.1,y1=5-.1,x0=quantile(five_j_match,.025),x1=quantile(five_j_match,.975),lwd=2)
segments(y0=4-.1,y1=4-.1,x0=quantile(four_j_match,.025),x1=quantile(four_j_match,.975),lwd=2)
segments(y0=3-.1,y1=3-.1,x0=quantile(three_j_match,.025),x1=quantile(three_j_match,.975),lwd=2)
segments(y0=2-.1,y1=2-.1,x0=quantile(two_j_match,.025),x1=quantile(two_j_match,.975),lwd=2)
segments(y0=1-.1,y1=1-.1,x0=quantile(one_j_match,.025),x1=quantile(one_j_match,.975),lwd=2)
abline(v=0,lwd=3,col="gray60")
legend("bottomright",c("Full Dataset","Matched Dataset"),       col=c("gray70","black"),pch=c(19,18),pt.cex=c(1,1.3))
dev.off()
